using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class tbKhachHangBUS
    {
        public static void Insert(tbKhachHang khachhang)
        {
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            khDAL.Insert(khachhang);
        }
        public static void Update(tbKhachHang khachhang)
        {
            tbKhachHangDAL khDAl = new tbKhachHangDAL();
            khDAl.Update(khachhang);
        }
        public static void Delete(int iD)
        {
            tbKhachHangDAL khDAl = new tbKhachHangDAL();
            khDAl.Delete(iD);
        }
        public static tbKhachHangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            return khDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbKhachHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            return khDAL.Get(cri.Criter, 0, 0, tbKhachHangColumns.MaKH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbKhachHang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbKhachHangColumns.MaKH.ToString(), Condition.EQUAL, iD);
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            tbKhachHangCollection khCollection = khDAL.Get(cri.Criter, 0, 0, tbKhachHangColumns.MaKH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (khCollection.Count > 0)
                return khCollection[0];
            return null;
        }
        public static tbKhachHangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            return khDAL.Get(cri.Criter, 1, number, tbKhachHangColumns.MaKH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbKhachHangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            return khDAL.Get(cri.Criter, 1, number, tbKhachHangColumns.MaKH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static Boolean KiemTraDangNhap(string user, string pass)
        {
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            return khDAL.KiemTraDangNhap(user, pass);
        }
        public static Boolean KiemTraKhachHang(string user)
        {
            tbKhachHangDAL khDAL = new tbKhachHangDAL();
            return khDAL.KiemTraKhachHang(user);
        }
    }
}
